﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel.Syndication;
using System.Collections.ObjectModel;

namespace dasBlog.Storage
{
    public interface IPersonStorageProvider : IStorageProvider<Person> { }

    [DataContract()]
    public class PostalAddress
    {
        [DataMember(EmitDefaultValue=false)]
        public string AddressLine1 { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string AddressLine2 { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string AddressCity { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string AddressRegion { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string AddressCountry { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string AddressPostalCode { get; set; }
    }

    [DataContract]
    public class Credentials
    {
        [DataMember(EmitDefaultValue=false)]
        public string CardSpaceId;
        [DataMember(EmitDefaultValue = false)]
        public string Password;
    }

    [DataContract()]
    public class Person : IEntry<Person>
    {
        [DataMember(EmitDefaultValue=false)] 
        public string Title { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string FirstName { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string LastName { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string MiddleName { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string NameSuffix { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public PostalAddress BusinessPostalAddress { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public PostalAddress PersonalPostalAddress { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string Email1 { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string Email2 { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string IM1 { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string IM2 { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string BusinessPhone { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string BusinessMobile { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string PersonalPhone { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string PersonalMobile { get; set; }
        [DataMember(EmitDefaultValue=false)]
        public string PictureUri { get; set; }

        public SyndicationItem ToSyndicationItem<T>()
        {
            var item = new SyndicationItem();
            //if (string.IsNullOrEmpty(Summary))
            //{
            //    item.Summary = SyndicationContent.CreatePlaintextContent(Content);
            //    item.Content = SyndicationContent.CreateHtmlContent(Content);
            //}
            //else
            //{
            //    item.Summary = SyndicationContent.CreatePlaintextContent(Summary);
            //    item.Content = SyndicationContent.CreateHtmlContent(Content);
            //}
            //item.Title = SyndicationContent.CreatePlaintextContent(Title);
            //item.LastUpdatedTime = LastChange;
            //item.PublishDate = Created;
            //item.Links.Add(SyndicationLink.CreateSelfLink(new Uri(Id)));
            //item.Authors.Add(new SyndicationPerson(Owner.Address, Owner.DisplayName, ""));
            item.ElementExtensions.Add(SerializationTools<Person>.ToXmlElement(this));
            return item;

        }

        public bool IsAuthorized(System.IdentityModel.Claims.ClaimSet claim)
        {
            return true;
        }

        #region IExtensibleDataObject Members

        public ExtensionDataObject ExtensionData
        {
            get;set;
        }

        #endregion
    }
}
